package com.comp6231.replica1.data;

/**
 * 
 * @author sknarula (narula.sk@gmail.com)
 * @since November 2013
 * 
 *        This is an enum class to aid in knowing the number and name of replicas
 *        instances
 * 
 *        The purpose of creating a separate enum class is to make replicas
 *        instances extensible in future. With this, more replicas instances can
 *        be created without changing the coordinator. If the new replica needs
 *        to be added, just add it here.
 * 
 */
public enum Replicas {

	Replica1(1, "localhost", 2050), Replica2(2, "localhost", 2051),
		Replica3(3, "localhost", 2053);

	private final int replicaId;
	private final String hostName;
	private final int portNumber;

	private Replicas(final int id, final String hostName, final int portNumber) {
		this.replicaId = id;
		this.hostName = hostName;
		this.portNumber = portNumber;
	}

	public int getReplicaId() {
		return replicaId;
	}

	public String getHostName() {
		return hostName;
	}

	public int getPortnumber() {
		return portNumber;
	}

	public static Replicas getEnumValue(String name) {
		for (Replicas obj : Replicas.values())
			if (obj.getHostName().equals(name))
				return obj;
		throw new IllegalArgumentException(
				"Illegal value for HostName enum.");
	}
	
	public static Replicas getEnumValue(int id) {
		for (Replicas obj : Replicas.values())
			if (obj.getReplicaId() == id)
				return obj;
		throw new IllegalArgumentException(
				"Illegal value for ReplicaId enum.");
	}

}